#include <FileI.h>

void
FileI::next_async(const ::Yafridng::AMD_File_nextPtr& cb,
		  const ::Ice::Current& current)
{
  pair <const Ice::Byte*, const Ice::Byte*> ret(0, 0);
  ssize_t r;
  bool end;

  if(_pieceSize - _num > 0){
    r = fread(_bytes, 1, _num, _fp);
    _pieceSize -= _num;
  }
  else{
    r = fread(_bytes, 1, _pieceSize, _fp);
    _pieceSize = 0;
  }

  if (r == 0) {
    fclose(_fp);
    current.adapter->remove(current.id);
  }

  else {
    ret.first = _bytes;
    ret.second = _bytes + r;
  }
  cb->ice_response(ret);
}
